import Vue from "vue"
import Vuex from 'vuex'
// import counter from "./modules/counter"
import createPersistedstate from 'vuex-persistedstate'
Vue.use(Vuex)
const store=new Vuex.Store({
    state:{
        count:0,
        user:{
            name:'',
            age:0
        }
    },
    mutations:{
        INCREMENT_COUNT(state,payload){
            state.count=state.count+payload
        },
        UPDATE_USER(state,payload){
            state.user=payload
        }
    },
    actions:{
        incrementAsync(cxt,payload){
            setTimeout(() => {
                cxt.commit('INCREMENT_COUNT',payload)
            }, 2000);
        }
    },
    getters:{
        doubleCount(state){
            return state.count*2
        }
    },
    modules:{
        counterKey:counter
    },
    plugins:[
        createPersistedstate({
            key:'count',
            storage:window.sessionStorage,
            paths:['user.name']
        })
    ]
})
export default store